/*
 * Copyright (c) 2022 Huawei Technologies Co.,Ltd.
 *
 * openGauss is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *          http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * -------------------------------------------------------------------------
 *
 * knl_log_type.h
 *    Functions for constructing redo logs
 *
 * IDENTIFICATION
 *    src/storage/gstor/zekernel/kernel/persist/knl_log_type.h
 *
 * -------------------------------------------------------------------------
 */
#ifndef __KNL_LOG_TYPE_H__
#define __KNL_LOG_TYPE_H__

#ifdef __cplusplus
extern "C" {
#endif

#define LOG_TYPE_BASIC 0
#define LOG_TYPE_SPACE 10
#define LOG_TYPE_HEAP  30
#define LOG_TYPE_UNDO  70
#define LOG_TYPE_BTREE 90
#define LOG_TYPE_LOB   130
#define LOG_TYPE_PCRH  150
#define LOG_TYPE_PCRB  180
#define LOG_TYPE_PUNCH 240
#define LOG_TYPE_LREP  250
#define LOG_TYPE_LOGIC 255

typedef enum en_log_type {
    // buffer
    RD_ENTER_PAGE = LOG_TYPE_BASIC + 1,
    RD_LEAVE_PAGE = LOG_TYPE_BASIC + 2,

    // transaction
    RD_TX_BEGIN = LOG_TYPE_BASIC + 3,
    RD_TX_END = LOG_TYPE_BASIC + 4,
    RD_XA_PHASE1 = LOG_TYPE_BASIC + 5,
    RD_XA_ROLLBACK_PHASE2 = LOG_TYPE_BASIC + 6,

    // txn page
    RD_ENTER_TXN_PAGE = LOG_TYPE_BASIC + 7, // the enter page redo for txn page
    RD_LEAVE_TXN_PAGE = LOG_TYPE_BASIC + 8, // the leave page redo for txn page

    // space
    // attention: Must check rcy_contain_spc_log function when add new space redo log
    RD_SPC_CREATE_SPACE = LOG_TYPE_SPACE + 0,
    RD_SPC_REMOVE_SPACE = LOG_TYPE_SPACE + 1,
    RD_SPC_CREATE_DATAFILE = LOG_TYPE_SPACE + 2,
    RD_SPC_REMOVE_DATAFILE = LOG_TYPE_SPACE + 3,
    RD_SPC_CHANGE_SEGMENT = LOG_TYPE_SPACE + 4,
    RD_SPC_UPDATE_HEAD = LOG_TYPE_SPACE + 5,
    RD_SPC_UPDATE_HWM = LOG_TYPE_SPACE + 6,
    RD_SPC_ALLOC_EXTENT = LOG_TYPE_SPACE + 7,
    RD_SPC_FREE_EXTENT = LOG_TYPE_SPACE + 8,
    RD_SPC_CONCAT_EXTENT = LOG_TYPE_SPACE + 9,
    RD_SPC_FREE_PAGE = LOG_TYPE_SPACE + 10,
    RD_SPC_EXTEND_DATAFILE = LOG_TYPE_SPACE + 11,
    RD_SPC_TRUNCATE_DATAFILE = LOG_TYPE_SPACE + 12,
    RD_SPC_INIT_MAP_HEAD = LOG_TYPE_SPACE + 13,
    RD_SPC_ADD_MAP_GROUP = LOG_TYPE_SPACE + 14,
    RD_SPC_INIT_MAP_PAGE = LOG_TYPE_SPACE + 15,
    RD_SPC_CHANGE_MAP = LOG_TYPE_SPACE + 16,
    RD_SPC_EXTEND_UNDO_SEGMENTS = LOG_TYPE_SPACE + 17,
    RD_SPC_PUNCH_EXTENTS = LOG_TYPE_SPACE + 18,

    // heap
    RD_HEAP_FORMAT_PAGE = LOG_TYPE_HEAP + 0,  // heap data page
    RD_HEAP_CONCAT_PAGE = LOG_TYPE_HEAP + 1,
    RD_HEAP_FORMAT_MAP = LOG_TYPE_HEAP + 2,      // heap map page
    RD_HEAP_FORMAT_ENTRY = LOG_TYPE_HEAP + 3,    // heap entry
    RD_HEAP_ALLOC_MAP_NODE = LOG_TYPE_HEAP + 4,  // heap alloc map node
    RD_HEAP_CHANGE_SEG = LOG_TYPE_HEAP + 5,      // set segment head
    RD_HEAP_SET_MAP = LOG_TYPE_HEAP + 6,
    RD_HEAP_CHANGE_MAP = LOG_TYPE_HEAP + 7,
    RD_HEAP_CHANGE_DIR = LOG_TYPE_HEAP + 8,
    RD_HEAP_INSERT = LOG_TYPE_HEAP + 9,
    RD_HEAP_UPDATE_INPLACE = LOG_TYPE_HEAP + 10,
    RD_HEAP_UPDATE_INPAGE = LOG_TYPE_HEAP + 11,
    RD_HEAP_INSERT_MIGR = LOG_TYPE_HEAP + 12,
    RD_HEAP_SET_LINK = LOG_TYPE_HEAP + 13,
    RD_HEAP_REMOVE_MIGR = LOG_TYPE_HEAP + 14,
    RD_HEAP_DELETE = LOG_TYPE_HEAP + 15,
    RD_HEAP_DELETE_LINK = LOG_TYPE_HEAP + 16,
    RD_HEAP_LOCK_ROW = LOG_TYPE_HEAP + 17,
    RD_HEAP_NEW_ITL = LOG_TYPE_HEAP + 18,
    RD_HEAP_REUSE_ITL = LOG_TYPE_HEAP + 19,
    RD_HEAP_CLEAN_ITL = LOG_TYPE_HEAP + 20,
    RD_HEAP_UNDO_CHANGE_DIR = LOG_TYPE_HEAP + 21,
    RD_HEAP_UNDO_INSERT = LOG_TYPE_HEAP + 22,
    RD_HEAP_UNDO_UPDATE = LOG_TYPE_HEAP + 23,
    RD_HEAP_UNDO_UPDATE_FULL = LOG_TYPE_HEAP + 24,
    RD_HEAP_UNDO_DELETE = LOG_TYPE_HEAP + 25,
    RD_HEAP_UNDO_DELETE_LINK = LOG_TYPE_HEAP + 26,
    RD_HEAP_INIT_ITLS = LOG_TYPE_HEAP + 27,
    RD_HEAP_CHANGE_LIST = LOG_TYPE_HEAP + 28,
    RD_HEAP_UNDO_INSERT_LINK = LOG_TYPE_HEAP + 29,
    RD_HEAP_SHRINK_MAP = LOG_TYPE_HEAP + 30,
    RD_HEAP_DELETE_MIGR = LOG_TYPE_HEAP + 31,
    RD_HEAP_UNDO_UPDATE_LINKRID = LOG_TYPE_HEAP + 32,

    // undo
    RD_UNDO_ALLOC_SEGMENT = LOG_TYPE_UNDO + 0,
    RD_UNDO_CREATE_SEGMENT = LOG_TYPE_UNDO + 1,
    RD_UNDO_CHANGE_SEGMENT = LOG_TYPE_UNDO + 2,
    RD_UNDO_EXTEND_TXN = LOG_TYPE_UNDO + 3,
    RD_UNDO_FORMAT_TXN = LOG_TYPE_UNDO + 4,
    RD_UNDO_CHANGE_TXN = LOG_TYPE_UNDO + 5,
    RD_UNDO_FORMAT_PAGE = LOG_TYPE_UNDO + 6,
    RD_UNDO_CHANGE_PAGE = LOG_TYPE_UNDO + 7,
    RD_UNDO_WRITE = LOG_TYPE_UNDO + 8,
    RD_UNDO_CLEAN = LOG_TYPE_UNDO + 9,
    RD_UNDO_MOVE_TXN = LOG_TYPE_UNDO + 10,
    RD_UNDO_CIPHER_RESERVE = LOG_TYPE_UNDO + 11,
    
    // btree
    RD_BTREE_INIT_SEG = LOG_TYPE_BTREE + 0,
    RD_BTREE_FORMAT_PAGE = LOG_TYPE_BTREE + 1,
    RD_BTREE_CHANGE_SEG = LOG_TYPE_BTREE + 2,
    RD_BTREE_CHANGE_CHAIN = LOG_TYPE_BTREE + 3,
    RD_BTREE_DELETE = LOG_TYPE_BTREE + 4,
    RD_BTREE_COMPACT_PAGE = LOG_TYPE_BTREE + 5,
    RD_BTREE_NEW_ITL = LOG_TYPE_BTREE + 6,
    RD_BTREE_REUSE_ITL = LOG_TYPE_BTREE + 7,
    RD_BTREE_CLEAN_ITL = LOG_TYPE_BTREE + 8,
    RD_BTREE_CLEAN_KEYS = LOG_TYPE_BTREE + 9,
    RD_BTREE_INSERT = LOG_TYPE_BTREE + 10,
    RD_BTREE_COPY_ITL = LOG_TYPE_BTREE + 11,
    RD_BTREE_COPY_KEY = LOG_TYPE_BTREE + 12,
    RD_BTREE_UNDO_INSERT = LOG_TYPE_BTREE + 13,
    RD_BTREE_UNDO_DELETE = LOG_TYPE_BTREE + 14,
    RD_BTREE_CONSTRUCT_PAGE = LOG_TYPE_BTREE + 15,
    RD_BTREE_INIT_ENTRY = LOG_TYPE_BTREE + 16,
    RD_BTREE_CHANGE_ITL_COPIED = LOG_TYPE_BTREE + 17,
    RD_BTREE_CLEAN_KEY = LOG_TYPE_BTREE + 18,
    RD_BTREE_SET_RECYCLE = LOG_TYPE_BTREE + 19,
    RD_BTREE_NEXT_DEL_PAGE = LOG_TYPE_BTREE + 20,
    RD_BTREE_UPDATE_PARTID = LOG_TYPE_BTREE + 21,

    // lob
    RD_LOB_PAGE_INIT = LOG_TYPE_LOB + 0,
    RD_LOB_CHANGE_SEG = LOG_TYPE_LOB + 1,
    RD_LOB_PUT_CHUNK = LOG_TYPE_LOB + 2,
    RD_LOB_CHANGE_ITEM = LOG_TYPE_LOB + 3,
    RD_LOB_CHANGE_CHAIN = LOG_TYPE_LOB + 4,
    RD_LOB_CHANGE_MAP = LOG_TYPE_LOB + 5,
    RD_LOB_FREE_PAGE_INIT = LOG_TYPE_LOB + 6,
    RD_LOB_CHANGE_CHUNK = LOG_TYPE_LOB + 7,
    RD_LOB_PAGE_EXT_INIT = LOG_TYPE_LOB + 8,

    // PCR heap
    RD_PCRH_INIT_ITLS = LOG_TYPE_PCRH + 0,
    RD_PCRH_NEW_ITL = LOG_TYPE_PCRH + 1,
    RD_PCRH_REUSE_ITL = LOG_TYPE_PCRH + 2,
    RD_PCRH_CLEAN_ITL = LOG_TYPE_PCRH + 3,
    RD_PCRH_LOCK_ROW = LOG_TYPE_PCRH + 4,
    RD_PCRH_INSERT = LOG_TYPE_PCRH + 5,
    RD_PCRH_DELETE = LOG_TYPE_PCRH + 6,
    RD_PCRH_UPDATE_INPLACE = LOG_TYPE_PCRH + 7,
    RD_PCRH_UPDATE_INPAGE = LOG_TYPE_PCRH + 8,
    RD_PCRH_CONVERT_LINK = LOG_TYPE_PCRH + 9,
    RD_PCRH_UPDATE_LINK_SSN = LOG_TYPE_PCRH + 10,
    RD_PCRH_UPDATE_NEXT_RID = LOG_TYPE_PCRH + 11,
    RD_PCRH_UNDO_ITL = LOG_TYPE_PCRH + 12,
    RD_PCRH_UNDO_INSERT = LOG_TYPE_PCRH + 13,
    RD_PCRH_UNDO_DELETE = LOG_TYPE_PCRH + 14,
    RD_PCRH_UNDO_UPDATE = LOG_TYPE_PCRH + 15,
    RD_PCRH_UNDO_LOCK_LINK = LOG_TYPE_PCRH + 16,
    RD_PCRH_UNDO_NEXT_RID = LOG_TYPE_PCRH + 17,
    RD_PCRH_RESET_SELF_CHANGE = LOG_TYPE_PCRH + 18,
    RD_PCRH_UNDO_UPDATE_LINK_SSN = LOG_TYPE_PCRH + 19,

    // PCR btree
    RD_PCRB_NEW_ITL = LOG_TYPE_PCRB + 0,
    RD_PCRB_REUSE_ITL = LOG_TYPE_PCRB + 1,
    RD_PCRB_CLEAN_ITL = LOG_TYPE_PCRB + 2,
    RD_PCRB_INSERT = LOG_TYPE_PCRB + 3,
    RD_PCRB_DELETE = LOG_TYPE_PCRB + 4,
    RD_PCRB_COMPACT_PAGE = LOG_TYPE_PCRB + 5,
    RD_PCRB_COPY_ITL = LOG_TYPE_PCRB + 6,
    RD_PCRB_COPY_KEY = LOG_TYPE_PCRB + 7,
    RD_PCRB_CLEAN_KEY = LOG_TYPE_PCRB + 8,
    RD_PCRB_SET_SCN = LOG_TYPE_PCRB + 9,
    RD_PCRB_SET_COPY_ITL = LOG_TYPE_PCRB + 10,
    RD_PCRB_CLEAN_KEYS = LOG_TYPE_PCRB + 11,
    RD_PCRB_UNDO_ITL = LOG_TYPE_PCRB + 12,
    RD_PCRB_UNDO_INSERT = LOG_TYPE_PCRB + 13,
    RD_PCRB_UNDO_DELETE = LOG_TYPE_PCRB + 14,

    RD_PUNCH_FORMAT_PAGE = LOG_TYPE_PUNCH + 0,
    // logicRep
    RD_LOGIC_REP_INSERT = LOG_TYPE_LREP + 0,
    RD_LOGIC_REP_UPDATE = LOG_TYPE_LREP + 1,
    RD_LOGIC_REP_DELETE = LOG_TYPE_LREP + 2,
    RD_LOGIC_REP_DDL = LOG_TYPE_LREP + 3,

    // logic operation
    RD_LOGIC_OPERATION = LOG_TYPE_LOGIC + 0,

    RD_TYPE_END = 256
} log_type_t;

typedef enum st_logic_op {
    RD_ADD_LOGFILE = 0,
    RD_DROP_LOGFILE = 1,
    RD_REGISTER_LOGFLIE = 2,
    RD_CREATE_TABLE = 3,
    RD_DROP_TABLE = 4,
    RD_ALTER_TABLE = 5,
    RD_RENAME_TABLE = 6,
    RD_DROP_VIEW = 7,
    RD_CREATE_USER = 8,
    RD_DROP_USER = 9,
    RD_ALTER_USER = 10,
    RD_GRANT_PRIVS = 11,
    RD_REVOKE_PRIVS = 12,
    RD_CREATE_ROLE = 13,
    RD_DROP_ROLE = 14,
    RD_FLASHBACK_DROP = 15,
    RD_SPC_SET_AUTOEXTEND = 16,
    RD_SPC_RENAME_SPACE = 17,
    RD_DATAFILE_EXTENT_SIZE = 18,
    RD_CREATE_SEQUENCE = 19,
    RD_DROP_SEQUENCE = 20,
    RD_ALTER_SEQUENCE = 21,
    RD_SPC_CHANGE_AUTOEXTEND = 22,
    RD_CREATE_PROFILE = 23,
    RD_ALTER_PROFILE = 24,
    RD_DROP_PROFILE = 25,
    RD_SPC_SET_FLAG = 26,
    RD_CREATE_SYNONYM = 27,
    RD_DROP_SYNONYM = 28,
    RD_UPDATE_CORE_INDEX = 29,
    RD_CREATE_DISTRIBUTE_RULE = 30,
    RD_DROP_DISTRIBUTE_RULE = 31,
    RD_CREATE_INDEX = 32,
    RD_ALTER_INDEX = 33,
    RD_DROP_INDEX = 34,
    RD_SWITCH_UNDO_SPACE = 35,
    RD_CREATE_MK_BEGIN = 36,
    RD_CREATE_MK_DATA = 37,
    RD_CREATE_MK_END = 38,
    RD_ALTER_SERVER_MK = 39,
    RD_SPC_SHRINK_CKPT = 40,
    RD_CREATE_TENANT = 41,
    RD_ALTER_TENANT = 42,
    RD_DROP_TENANT = 43,
    RD_UPDATE_SYSDATA_VERSION = 44,
    RD_SPC_PUNCH_HOLE = 45,
    RD_CREATE_INDEXES = 46,

    RD_SQL_LOG_BEGIN = 100,
    RD_SQL_LOG_END = 200,
} logic_op_t;

/* Notice: RD_ENTER_PAGE do not include txn page, RD_ENTER_TXN_PAGE is only for txn page */
#define RD_TYPE_IS_ENTER_PAGE(type)      ((type) == RD_ENTER_PAGE || (type) == RD_ENTER_TXN_PAGE)
#define RD_TYPE_IS_LEAVE_PAGE(type)      ((type) == RD_LEAVE_PAGE || (type) == RD_LEAVE_TXN_PAGE)

#ifdef __cplusplus
}
#endif

#endif
